package android.framework.binding;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;

public class BindableEditText extends EditText implements IBindable<String>{

	private StringViewBindingHandler stringViewBindingHandler = new StringViewBindingHandler();

	public BindableEditText(Context context, AttributeSet attributeSet) {
		super(context, attributeSet);
        this.addTextChangedListener(stringViewBindingHandler);
	}

	public boolean notifyChanges(String value, long actionId) {
		boolean notifyChanges = stringViewBindingHandler.notifyChanges(value, actionId);
		if(notifyChanges){
			setText(value);
		}
		return notifyChanges;
	}

	public void addListener(IObserver<String> listener) {
		stringViewBindingHandler.addListener(listener);
	}

	public void setListener(MultiBindingAdapter<String> listener) {
		stringViewBindingHandler.setListener(listener);
	}

	public void removeListener(IObserver<String> listener) {
		stringViewBindingHandler.removeListener(listener);
	}

	public String getLastValue() {
		return stringViewBindingHandler.getLastValue();
	}
	
	public void clearListeners() {
		stringViewBindingHandler.clearListeners();
	}

}
